/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.photos.plugins');
(function () {
	var EVENTS = net.autodata.EventBus.EVENTS;
	
	var Plugin = Ext.extend(Ext.util.Observable, {
		
		photosPanel: undefined,
		
		init: function (photosPanel)
		{
			this.photosPanel = photosPanel;
			
			var eb = net.autodata.EventBus.getInstance();
			eb.on(EVENTS.READY, this.onCompetitorChanged, this);
			eb.on(EVENTS.SESSION_COMPETITOR_CHANGED, this.onCompetitorChanged, this);
			eb.on(EVENTS.SESSION_COMPETITOR_REMOVED, this.onCompetitorChanged, this);			
		},
		
		onCompetitorChanged: function ()
		{
			var session = net.autodata.Session.getInstance();			
			var vehicles = session.vehicles;
			this.photosPanel.setVehicles(vehicles.getBaseVehicle(), vehicles.getCompetitors().getRange());
		},
		
		onDestroy: function ()
		{
			var eb = net.autodata.EventBus.getInstance();
			eb.un(EVENTS.READY, this.onCompetitorChanged, this);
			eb.un(EVENTS.SESSION_COMPETITOR_CHANGED, this.onCompetitorChanged, this);
			eb.un(EVENTS.SESSION_COMPETITOR_REMOVED, this.onCompetitorChanged, this);
		}
	});

	net.autodata.compare.photos.plugins.PhotosPanelEventBusConnector = Plugin;
})();